fix(types): remove extends ImportMeta from ModuleRunnerImportMeta#21710
fix(types): remove extends ImportMeta from ModuleRunnerImportMeta#21710YevheniiKotyrlo wants to merge 1 commit intovitejs:mainfrom
Conversation
sheremet-va
left a comment
There was a problem hiding this comment.
the interface already explicitly declares all needed properties (
url,env,hot) and has[key: string]: anyas a catch-all for any additional properties (dirname,filename,main,resolve,glob).
This doesn't make sense? extends validates the type of these fields at least. If you are removing the extends, then you should at least move those fields over.
|
Does it make sense to have a type test instead of |
Doesn't vite already run a typecheck? The issue I have here is that |
|
Won't it only be caught when we have |
Okay, that makes sense |
- Remove `extends ImportMeta` to prevent TS2717 "subsequent property declarations must have the same type" in consumer projects using skipLibCheck: false with augmented ImportMeta - Add explicit fields (dirname, filename, resolve, glob, main) that were previously inherited, so consumers get real types instead of falling through the `[key: string]: any` index signature - Add `main: false` to createDefaultImportMeta (previously only set in createNodeImportMeta) - Remove `satisfies Omit<ModuleRunnerImportMeta, 'main'> as any` — the function return type annotation handles the check, and with explicit fields the Omit workaround is no longer needed - Add type test verifying ModuleRunnerImportMeta is assignable to ImportMeta (including @types/node augmentations) — catches future inconsistencies without causing declaration-level conflicts
9f3d1b8 to
414de13
Compare
|
Thanks for the feedback! Updated the PR:
All gates pass: typecheck (6 projects), build (bundle + DTS + check), ESLint. |
Summary
ModuleRunnerImportMeta extends ImportMetainherits all augmented properties from the globalImportMetainterface. When consumers useskipLibCheck: falsewith libraries that augmentImportMeta(e.g.@types/node, Expo, React Native), TypeScript raises conflicts:The
extendsis unnecessary — the interface already explicitly declares all needed properties (url,env,hot) and has[key: string]: anyas a catch-all for any additional properties (dirname,filename,main,resolve,glob).Changes
packages/vite/src/module-runner/types.ts: Removeextends ImportMetafromModuleRunnerImportMetapackages/vite/src/module-runner/createImportMeta.ts: Simplifysatisfies Omit<ModuleRunnerImportMeta, 'main'> as anytosatisfies ModuleRunnerImportMeta as anyand remove the now-unnecessary comment —mainis no longer inherited from@types/node'sImportMetaaugmentationWhy this is safe
[key: string]: anyindex signature already accepts any additional properties at runtimecreateDefaultImportMetaandcreateNodeImportMetaset extra properties (filename,dirname,glob,resolve,main) via the index signature — no inheritance neededbuild-types-check(tsconfig.check.jsonwithtypes: []) passes becauseImportMetawithout augmentations is{}, soextends ImportMetawas already a no-op in that context